import Vue from 'vue'
import VueI18n from 'vue-i18n'
import elementEnLocale from 'element-ui/lib/locale/lang/en'
import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'
import elementEsLocale from 'element-ui/lib/locale/lang/es'
import locale from 'element-ui/lib/locale'
import enLocale from './en'
import zhLocale from './zh'
import esLocale from './es'

Vue.use(VueI18n)

// 引入本地包
const messages = {
    zh: {
      ...zhLocale,
      ...elementZhLocale
    },
    en: {
      ...enLocale,
      ...elementEnLocale
    },
    es: {
      ...esLocale,
      ...elementEsLocale
    }
  },
  // 创建国际化实例
  i18n = new VueI18n({
    locale: window.sessionStorage.getItem('lang') || 'zh',
    legacy: false,
    globalInjection: true,
    messages
  })

locale.i18n((key, value) => i18n.t(key, value))

export default i18n
